package com.atgouwu.mall.cart.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class MySwaggerConfig {

//    @Bean
//    public Docket apiConfig() { //默认配置
//        return new Docket(DocumentationType.SWAGGER_2);
//    }

    @Bean
    public Docket adminApiConfig() { //设置分组(选择器)
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("adminApi") //自定义分组名
                .apiInfo(adminApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/admin/.*"))) //*Controller类上统一路径
                .build();
    }

    @Bean
    public Docket webApiConfig() { //设置分组(选择器)
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/.*/.*/api/.*")))
                .build();
    }

    private ApiInfo adminApiInfo() { //文档描述
        return new ApiInfoBuilder()
                .title("后台管理系统API文档")
                .description("本文档描述了后台管理系统各个模块接口调用方式")
                .version("1.6")
                .contact(new Contact("何冉", "https://blog.csdn.net/alvin199765/category_10977371.html", "UnityAlvin@qq.com"))
                .build();
    }

    private ApiInfo webApiInfo() { //文档描述
        return new ApiInfoBuilder().title("网站API文档")
                .description("本文档描述了网站各个模块接口调用方式")
                .version("1.6")
                .contact(new Contact("何冉", "https://blog.csdn.net/alvin199765/category_10977371.html", "UnityAlvin@qq.com"))
                .build();
    }
}
